﻿using SmartHRMS.Infrastructure;
using SmartHRMS.NhibernateRepository;
using SmartHRMS.Services;
using StructureMap;
using StructureMap.Configuration.DSL;
using SmartHRMS.Model.Company;
using SmartHRMS.Model.Account;
using SmartHRMS.Infrastructure.Caching;
using SmartHRMS.NhibernateRepository.Repositories;

namespace SmartHRMS.UI.Web
{
    public class BootStrapper
    {
        public static void ConfigureDependencies()
        {
            ObjectFactory.Initialize(x =>
                                     {
                                         x.AddRegistry<ControllerRegistry>();
                                     });
        }

        public class ControllerRegistry : Registry
        {
            public ControllerRegistry()
            {

                ForRequestedType<IPrincipalRepository>().TheDefault.Is.OfConcreteType<PrincipalRepository>();

                ForRequestedType<IPrincipalService>().TheDefault.Is.OfConcreteType<PrincipalService>();

                //Users

                ForRequestedType<IUserRepository>().TheDefault.Is.OfConcreteType<UserRepository>();

                ForRequestedType<IUserService>().TheDefault.Is.OfConcreteType<UserService>();

                //Modules and Roles

                ForRequestedType<IModuleRepository>().TheDefault.Is.OfConcreteType<ModuleRepository>();

                ForRequestedType<IModuleService>().TheDefault.Is.OfConcreteType<ModuleService>();

                ForRequestedType<IRoleRepository>().TheDefault.Is.OfConcreteType<RoleRepository>();                

                ForRequestedType<IRoleService>().TheDefault.Is.OfConcreteType<RoleService>();

                //Company

                ForRequestedType<ICompanyRepository>().TheDefault.Is.OfConcreteType<CompanyRepository>();

                ForRequestedType<ICompanyService>().TheDefault.Is.OfConcreteType<CompanyService>();

                ForRequestedType<ICacheStorage>().TheDefault.Is.OfConcreteType<HttpContextCacheAdapter>();

                ForRequestedType<IUnitOfWork>().TheDefault.Is.OfConcreteType<NhibernateUnitOfWork>();
            }
        }
    }
}